<template>
  <div class="mycenter-in-user">
    <!--用户信息-->
    <div class="mycenter-in-user-one mycenter-in-user-list color-03"
         :style="{background: 'url('+userbg+')',backgroundRepeat: 'no-repeat'}">
      <div class="user-list-info">
        <img :src="userInfo.pic" alt="" v-if="userInfo && userInfo.pic">
        <img src="@/assets/imageAdmin/defultimg.jpg" alt="" v-else>
        <p class="user-name" @click="showUserInfo">{{userInfo?userInfo.realname:'--'}} <i
                class="iconfont iconxitongguanli colorfont-01"></i></p>
        <!--<p class="user-name-line" v-if="userInfo">-->
        <!--职工信息：-->
        <!--<span v-if="userInfo.classes">{{userInfo.classes.section_id}}{{userInfo.classes.class_name}}</span>-->
        <!--<span v-else>超级管理员</span>-->
        <!--</p>-->
        <p class="user-name-line">角色：{{userInfo?(userInfo.role?userInfo.role.name:userInfo.role_name):'--'}}</p>
      </div>
    </div>
    <div class="mycenter-in-user-two mycenter-in-user-list">
      <p class="add-box-theme"><span></span>我的待办</p>
      <div class="mywork-list">
        <div class="mywork-list-line">
          <p class="mywork-list-line-l">
            <i class="iconfont iconxuesheng colorfont-01"></i>
            <span>公文</span>
          </p>
          <p class="mywork-list-line-r">
            <span>待处理：<em>0</em></span>
            <i class="el-icon-arrow-right"></i>
          </p>
        </div>
        <div class="mywork-list-line" @click="pathIndexFn('task')">
          <p class="mywork-list-line-l">
            <i class="iconfont iconrenwu colorfont-14"></i>
            <span>任务</span>
          </p>
          <p class="mywork-list-line-r">
            <span>待处理：<em>{{countNumber?countNumber.task:0}}</em></span>
            <i class="el-icon-arrow-right"></i>
          </p>
        </div>
        <div class="mywork-list-line" @click="pathIndexFn('questionmylist')">
          <p class="mywork-list-line-l">
            <i class="iconfont iconwenjuan colorfont-06"></i>
            <span>问卷</span>
          </p>
          <p class="mywork-list-line-r">
            <span>待处理：<em>{{countNumber?countNumber.quest_inside:0}}</em></span>
            <i class="el-icon-arrow-right"></i>
          </p>
        </div>
        <div class="mywork-list-line" @click="pathIndexFn('vote')">
          <p class="mywork-list-line-l">
            <i class="iconfont iconwenjuan colorfont-16"></i>
            <span>投票</span>
          </p>
          <p class="mywork-list-line-r">
            <span>待处理：<em>{{countNumber?countNumber.vote:0}}</em></span>
            <i class="el-icon-arrow-right"></i>
          </p>
        </div>
        <div class="mywork-list-line" @click="pathIndexFn('book')">
          <p class="mywork-list-line-l">
            <i class="iconfont icontushu1 colorfont-12"></i>
            <span>图书</span>
          </p>
          <p class="mywork-list-line-r">
            <span>待归还：<em>{{countNumber?countNumber.book_return:0}}</em></span>
            <i class="el-icon-arrow-right"></i>
          </p>
        </div>
      </div>
    </div>
    <div class="mycenter-in-user-two mycenter-in-user-list">
      <p class="add-box-theme"><span></span>我的发布</p>
      <div class="mywork-list" v-if="publish">
        <div class="mywork-list-line" @click="pathIndexFn('task')">
          <p class="mywork-list-line-l">
            <i class="iconfont iconrenwu colorfont-14"></i>
            <span>任务</span>
          </p>
          <p class="mywork-list-line-r">
            <span>未结束：<em>{{publish?publish.task:0}}</em></span>
            <i class="el-icon-arrow-right"></i>
          </p>
        </div>
        <div class="mywork-list-line" @click="pathIndexFn('questionmylist')">
          <p class="mywork-list-line-l">
            <i class="iconfont iconwenjuan colorfont-06"></i>
            <span>问卷</span>
          </p>
          <p class="mywork-list-line-r">
            <span>未结束：<em>{{publish?publish.questionnaire_inside:0}}</em></span>
            <i class="el-icon-arrow-right"></i>
          </p>
        </div>
        <div class="mywork-list-line" @click="pathIndexFn('vote')">
          <p class="mywork-list-line-l">
            <i class="iconfont iconwenjuan colorfont-16"></i>
            <span>投票</span>
          </p>
          <p class="mywork-list-line-r">
            <span>未结束：<em>{{publish?publish.vote:0}}</em></span>
            <i class="el-icon-arrow-right"></i>
          </p>
        </div>
        <div class="mywork-list-line" @click="pathIndexFn('NoticeList')">
          <p class="mywork-list-line-l">
            <i class="iconfont iconxuesheng colorfont-01"></i>
            <span>通知</span>
          </p>
          <p class="mywork-list-line-r">
            <span>未结束：<em>{{publish?publish.notice:0}}</em></span>
            <i class="el-icon-arrow-right"></i>
          </p>
        </div>
        <div class="mywork-list-line" @click="pathIndexFn('questionnaireList')">
          <p class="mywork-list-line-l">
            <i class="iconfont iconxuesheng colorfont-01"></i>
            <span>调查</span>
          </p>
          <p class="mywork-list-line-r">
            <span>未结束：<em>{{publish?publish.questionnaire:0}}</em></span>
            <i class="el-icon-arrow-right"></i>
          </p>
        </div>
      </div>
    </div>
    <div class="mycenter-in-user-three mycenter-in-user-list">
      <p class="add-box-theme"><span></span>快速创建</p>
      <div class="add-box-theme-box">
        <div class="add-box-theme-box-list" @click="pathIndexFn('addtask')">
          <i class="add-box-theme-box-list-icon iconfont iconfaburenwu"></i>
          <span>发布任务</span>
        </div>
        <div class="add-box-theme-box-list" @click="pathIndexFn('NoticeDetail')">
          <i class="add-box-theme-box-list-icon iconfont icontianjiarenyuan"></i>
          <span>发布通知</span>
        </div>
        <div class="add-box-theme-box-list" @click="pathIndexFn('questionnaireDetail')">
          <i class="add-box-theme-box-list-icon iconfont iconwenjuan1"></i>
          <span>发布问卷</span>
        </div>
        <div class="add-box-theme-box-list" @click="pathIndexFn('applybook')">
          <i class="add-box-theme-box-list-icon iconfont iconicon"></i>
          <span>申请图书</span>
        </div>
        <div class="add-box-theme-box-list" @click="pathIndexFn('applyMateriel')">
          <i class="add-box-theme-box-list-icon iconfont iconmaterial"></i>
          <span>申请物料</span>
        </div>
        <div class="add-box-theme-box-list" @click="pathIndexFn('applyteaching')">
          <i class="add-box-theme-box-list-icon iconfont iconfuzhutubiao-jiaoju"></i>
          <span>申请教具</span>
        </div>
        <div class="add-box-theme-box-list" @click="pathIndexFn('Corner')">
          <i class="add-box-theme-box-list-icon iconfont iconquyu1"></i>
          <span>预约区角</span>
        </div>
        <div class="add-box-theme-box-list" @click="pathIndexFn('Cornerline')">
          <i class="add-box-theme-box-list-icon iconfont iconshangchuanwendangx"></i>
          <span>实时区角</span>
        </div>
        <div class="add-box-theme-box-list" @click="pathIndexFn('Comment')">
          <i class="add-box-theme-box-list-icon iconfont icondianping"></i>
          <span>点评餐品</span>
        </div>
      </div>
    </div>
    <userInfo :visible.sync="userInfoVisible" @refreshFn="InitFn"></userInfo>
  </div>
</template>

<script>
  import userbg from '@/assets/imageAdmin/userbg.png'
  import userInfo from '@/components/dialog/userInfo.vue'
  import {usercenter} from '@/utils/util.js'
  import {mapActions} from "vuex";

  export default {
    components: {
      userbg,
      userInfo
    },
    name: 'powerUser',
    data () {
      return {
        usercenter: usercenter,
        userbg: userbg,
        userInfo: null,
        countNumber: null,
        userInfoVisible: false,
        powerMudel: null,
        publish: null,
      }
    },
    created () {
      // is_all 总管理员8
      // n7-3  教具管理员； n6-3 图书管理员；n9-3 物料管理员； n12-1-3 餐品管理员；
      // this.InitFn()
      this.GetInfo().then(res=>{
        console.log('userInfo:', res)
        this.userInfo = res.detail
        this.powerMudel = res.detail.power
        this.InitFn()
        // 我的发布待处理
        this.addCheckFn()
      })
    },
    methods: {
      ...mapActions(['GetInfo']),
      InitFn () {
        this.$fetch(this.api.admin_user_edit, {
          id: this.userInfo.id
        }).then((response) => {
          if (response.code === 0) {
            this.userInfo = this.getJson(response.detail)
            this.countNumber = response.count
          } else {
          }
        }).catch((err) => {
          console.log(err)
        })
      },
      getJson(option){
        return JSON.parse(JSON.stringify(option))
      },
      addCheckFn () {
        this.$fetch(this.api.statistics_publish, {}).then((response) => {
          console.log('获取到得数据内容：', response)
          if (!response.code) {
            this.publish = response
          }
        }).catch((err) => {
          console.log(err)
        })
      },
      showUserInfo () {
        this.userInfoVisible = true
      },
      pathIndexFn (option) {
        // NoticeDetail questionnaireDetail 只能班主任 点击
        if (option === 'Corner' && this.powerMudel.indexOf('n14-2-1') == -1) {
          this.$confirm('该功能只向对应班级教师开放?', '提示', {
            confirmButtonText: '确定',
            showCancelButton: false,
            type: 'warning'
          }).then(() => {
          }).catch(() => {
          })
        } else if (option === 'Comment' && this.powerMudel.indexOf('n12-2') == -1) {
          this.$confirm('该功能只向对应班级教师开放?', '提示', {
            confirmButtonText: '确定',
            showCancelButton: false,
            type: 'warning'
          }).then(() => {
          }).catch(() => {
          })
        } else {
          this.$router.push(usercenter[option])
        }
      }
    }
  }
</script>
